package cn.t.modules.scheduler.core.schedule.repository.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Update;

/**
 * @author 陶敏麒
 * @date 2023/5/4 16:31
 */
@Mapper
public interface CreateTableMapper {

    // 1. 建表
    @Update("CREATE TABLE IF NOT EXISTS 'schedule' (" +
            " 'id' integer NOT NULL PRIMARY KEY AUTOINCREMENT," +
            " 'schedule_id' text NOT NULL," +
            " 'schedule_name' text NOT NULL," +
            " 'exec_time_ts' integer NOT NULL," +
            " 'status' text NOT NULL," +
            " 'version' integer NOT NULL DEFAULT 0," +
            " 'content' text NOT NULL," +
            " 'type' text NOT NULL," +
            " 'desc' text," +
            " 'src' text," +
            " 'create_time' text," +
            " 'update_time' text" +
            ");")
    void createScheduleTable();

    // 2. 建索引
    @Update("CREATE INDEX IF NOT EXISTS 'st' ON schedule ('src', 'schedule_id', 'status', 'type');")
    void createScheduleIndex();



    @Update("CREATE TABLE IF NOT EXISTS 'recognition_record' " +
            "('record_id' text NOT NULL, 'plate' text NOT NULL," +
            " 'recognition_ts' integer NOT NULL," +
            " 'device_id' text NOT NULL," +
            " 'device_name' text, 'pass_type' text, 'channel_id' text," +
            " PRIMARY KEY('record_id'));")
    void createRecordTable();
}
